package com.tedu.controller;


import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller//标识Springmvc控制器
public class UserContrlloer {

    @RequestMapping("/login")

    public String login(String username, String password, Model model) {
        //System.out.println(user.toString());

        if (username != null && username.equals("admin") && password != null && password.equals("123")) {
            System.out.println("欢迎你" + username);
            model.addAttribute("msg", "恭喜你 " + username + " 登录成功");
        } else {
            System.out.println("用户名或密码错误");
            model.addAttribute("msg", "Sorry "+username+" 登录失败");

        }
        return "test";//前缀后缀 返回视图

    }

    @RequestMapping("/toreg")

    public String toreg() {

        return "reg";
    }

    @RequestMapping("/reg")
    public String reg(){

        return "redirect:/index.jsp";//邀请用户登录（重定向）
    }

}
